/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.web.controller;

import cc.altius.model.SpecialistType;
import cc.altius.service.SpecialistTypeService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *
 * @author sagar
 */
@Controller
public class SpecialistTypeController {

    @Autowired
    private SpecialistTypeService specialistTypeService;

    @ModelAttribute("specialistTypeList")
    List<SpecialistType> getSpecialistTypeList() {
        return this.specialistTypeService.getSpecialistTypeList();
    }

    @RequestMapping(value = "/specialistType/addSpecialistType.htm", method = RequestMethod.GET)
    public String showSpecialistTypePage(ModelMap modelMap) {
        SpecialistType specialistType = new SpecialistType();
        modelMap.addAttribute("specialistType", specialistType);
        return "specialistType/addSpecialistType";
    }

    @RequestMapping(value = "/specialistType/addSpecialistType.htm", method = RequestMethod.POST)
    public String addSpecialistTypePage(@ModelAttribute("specialistType") SpecialistType specialistType) {
        this.specialistTypeService.addSpecialistType(specialistType);
        return "redirect:addSpecialistType.htm?msg=Succesfully Added Specialist Type";

    }

    @RequestMapping(value = "/specialistType/listSpecialistType.htm", method = RequestMethod.GET)
    public String showSpecialistTypeListPage(ModelMap modelMap) {

        return "specialistType/listSpecialistType";
    }

    @RequestMapping(value = "/specialistType/updateSpecialistType.htm", method = RequestMethod.GET)
    public String showUdateSpecialistTypePage(@RequestParam(value = "specialistTypeId") int specialistTypeId, ModelMap modelMap) {
        SpecialistType specialistType = this.specialistTypeService.getSpecialistTypeById(specialistTypeId);
        modelMap.addAttribute("specialistType", specialistType);
        return "specialistType/updateSpecialistType";
    }

    @RequestMapping(value = "/specialistType/updateSpecialistType.htm", method = RequestMethod.POST)
    public String postUpdateSpecialistTypePage(@ModelAttribute("specialistType") SpecialistType specialistType, HttpServletRequest request,
            @RequestParam(value = "specialistTypeId", required = true) int specialistTypeId) {
        System.out.println("specialistTypeId"+specialistTypeId);
       //int campaignTypeId = ServletRequestUtils.getIntParameter(request, "specialistTypeId", 0);
        this.specialistTypeService.updateSpecialistType(specialistType, specialistTypeId);

        return "redirect:listSpecialistType.htm?msg=Succesfully Updated Specialist Type";

    }
}
